<template>
  <div class="project-Container">
    <div class="head">
      <div class="opt"></div>
      <div class="search">
        <el-input
          placeholder="请输入手机号,姓名"
          suffix-icon="el-icon-search"
          v-model="search"
          @keyup.enter.native="getList()"
        ></el-input>
      </div>
    </div>

    <el-table :data="List" border style="width: 100%">
      <el-table-column prop="index" label="序号" width="80"></el-table-column>
      <el-table-column prop="userName" label="姓名"></el-table-column>
      <el-table-column prop="phone" label="手机号"></el-table-column>

      <el-table-column prop="money" label="提币数量"></el-table-column>

      <el-table-column prop="quota" label="手续费"></el-table-column>
      <el-table-column prop="profit" label="实际到账"></el-table-column>

      <el-table-column prop="createTime" label="申请时间"></el-table-column>
      <el-table-column prop="card" label="银行卡号"></el-table-column>
      <el-table-column label="审核状态">
        <template slot-scope="scope">
          <el-button type="text" v-show="scope.row.auditType  == 0" style="color:#E6A23C">待审核</el-button>
          <el-button type="text" v-show="scope.row.auditType  == 1">审核成功</el-button>
          <el-button type="text" v-show="scope.row.auditType  == 2">审核失败</el-button>
        </template>
      </el-table-column>

      <el-table-column label="核销状态">
        <template slot-scope="scope">
          <!-- 2待核销 -->
          <el-button type="text" v-show="scope.row.cancelType == 2"></el-button>
          <el-button type="text" v-show="scope.row.cancelType == 0">未核销</el-button>
          <el-button type="text" v-show="scope.row.cancelType == 1">已核销</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="auditName" label="审核人"></el-table-column>
      <el-table-column prop="auditTime" label="审核时间"></el-table-column>
      <el-table-column prop="cancelName" label="核销人"></el-table-column>
      <el-table-column prop="cancelTime" label="核销时间"></el-table-column>

      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="auditClick(scope.row)"
            v-show="scope.row.auditType == 0"
            style="color:#E6A23C"
          >审核</el-button>
          <el-button
            type="text"
            @click="cancelClick(scope.row)"
            v-show="scope.row.cancelType == 0"
          >核销</el-button>
          <!-- <el-button
            type="text"
            v-show="scope.row.auditType !== 0 && scope.row.cancelType !== 2"
            style="color:#909399"
          >无操作</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <div class="paginat">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage4"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>

    <!-- 提现审核 -->
    <el-dialog title="提示" width="30%" :visible.sync="outerVisible">
      是否对用户： {{userName}} , 进行审核?
      <el-dialog width="20%" title="审核" :visible.sync="innerVisible" append-to-body>请选择审核状态
        <div slot="footer" class="dialog-footer">
          <el-button @click="auditFalse()">不通过</el-button>
          <el-button type="primary" @click="auditOk()">通过</el-button>
        </div>
      </el-dialog>
      <div slot="footer" class="dialog-footer">
        <el-button @click="outerVisible = false">取 消</el-button>
        <el-button type="primary" @click="innerVisible = true">开始审核</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dialogVisible: false,
      search: "",
      val: 1,
      List: [],
      total: 0,
      val: 1, //当前多少页
      currentPage4: 1,
      userName: "",
      auditId: "",
      auditMoney: "",
      auditProfit: "",
      auditUserId: "",
      outerVisible: false,
      innerVisible: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //审核通过
    auditOk() {
      let url = "/cash/update";
      let params = {
        id: this.auditId,
        auditType: 1,
        money: this.auditMoney,
        profit: this.auditProfit,
        userId: this.auditUserId
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "通过"
          });
          this.innerVisible = false;
          this.outerVisible = false;
          this.getList();
        } else {
          this.$message({
            type: "warning",
            message: res.message
          });
        }
      });
    },
    //审核不通过
    auditFalse() {
      let url = "/cash/update";
      let params = {
        id: this.auditId,
        auditType: 2,
        money: this.auditMoney,
        profit: this.auditProfit,
        userId: this.auditUserId
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.$message({
            type: "info",
            message: "不通过"
          });
          this.innerVisible = false;
          this.outerVisible = false;
          this.getList();
        } else {
          this.$message({
            type: "warning",
            message: res.message
          });
        }
      });
    },
    //审核
    auditClick(row) {
      this.userName = row.userName;
      this.auditId = row.id;
      this.auditMoney = row.money;
      this.auditProfit = row.profit;
      this.auditUserId = row.userId;
      this.outerVisible = true;
    },
    //核销
    cancelClick(row) {
      this.$confirm("是否选择核销", "核销", {
        confirmButtonText: "确定核销",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let url = "/cash/updates";
          let params = {
            id: row.id,
            cancelType: 1
          };
          this.httpPost(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "已核销"
              });
              this.getList();
            } else {
              this.$message({
                type: "warning",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    //分页
    handleCurrentChange(val) {
      this.val = val;
      this.getList();
      console.log(`当前页: ${val}`);
    },
    getList() {
      let url = "/cash/getCash";
      let params = {
        // projectsId: this.id,
        key: this.search,
        pageNum: this.val,
        pageSize: 10
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.List = res.data.list;
          this.total = res.data.total;
          this.List.forEach((element, i) => {
            this.List[i].index = (this.val - 1) * 10 + i + 1;
          });
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.head {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .search {
    width: 300px;
  }
}
</style>

<style lang="scss">
.project-Container {
  .el-button + .el-button {
    margin-left: 0px !important;
  }
}
</style>